package com.lankystar.logistucs.spring.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lankystar.logistucs.spring.dao.IAddressDao;
import com.lankystar.logistucs.spring.entity.Address;
import com.lankystar.logistucs.spring.service.AddressService;

@Service
public class AddressServiceImpl implements AddressService{

	@Autowired
	private IAddressDao addressDao;
	@Override
	public Address addAddress(Address record) {
		record.setCreateTime(new Date().getTime());
		 addressDao.add(record);
		return record;
	}
	@Override
	public List<Map<String, Object>> queryAddresslistByuserId(int userId) {
		List<Map<String, Object>> maplist = new ArrayList<>();
		List<Address> addresslist = addressDao.selectAddresslistByuserId(userId);
		for (Address a : addresslist) {
			Map<String, Object> map = new HashMap<>();
			map.put("addressId", a.getAddressId());
			map.put("detailed", a.getDetailed());
			map.put("name", a.getName());
			map.put("phone", a.getPhone());
			maplist.add(map);
		}
		return maplist;
	}

}
